#include "vroute_filter_server.hpp"
#include "vrouteErrors.hpp"
#include "logger.hpp"
#include "vroute_IFServerdef.hpp"
#include "vroute_server_fixedPath.hpp"
#include "vroute_server_port.hpp"
#include "vroute_server_queryDevice.hpp"

namespace vroute_stack
{
    CFltServer::CFltServer()
    {
        m_ser_fixedpath = CSerFixedPath::getInstance();
        m_ser_port = CSerPort::getInstance();
        m_ser_qdev = CSerQueryDevice::getInstance();
    }

    CFltServer::~ CFltServer()
    {
    }
    
    /*
     * 
     */
    int CFltServer::dofilter(char* content, int len, int socketIndex)
    {
        CheckNull(content, e_vroute_filter_sucess);
        int serverCode = content[0];
        switch(serverCode)
        {
            case vroute_serverCode_linker_createFixedPathRequest:
            case vroute_serverCode_linker_createFixedPathResponse_Normal:
            case vroute_serverCode_linker_createFixedPathResponse_Reversed:
            case vroute_serverCode_linker_createFixedPathResponse_Normal_Rev:
            case vroute_serverCode_linker_FixedPath_Broken:
            case vroute_serverCode_linker_FixedPath_Sync:
                return m_ser_fixedpath->doServerAction(content, len, socketIndex, nullptr);
            case vroute_serverCode_port_sync_request:
                return m_ser_port->doServerAction(content, len, socketIndex, nullptr);
            case vroute_serverCode_data_query_device_ttl_max:
            case vroute_serverCode_data_query_device_response:
            case vroute_serverCode_data_query_device_chars:
                return m_ser_qdev->doServerAction(content, len, socketIndex, nullptr);
            default:                
                logger_error("CFltServer::dofilter, unsuport server code=%d", serverCode);
                return e_vroute_filter_sucess;
        }
        return e_vroute_filter_sucess;
    }
}